import csv
import json
import matplotlib.pyplot as plt

cal_file = './jsonfile.json'
f = open(cal_file, 'r')
cal_json = json.load(f)
print(cal_json)

sensor_list = ['cegun', 'chilunxiang', 'dianjichui', 'dianjiheng', 'fuchen', 'hengjian', 'hengxiang', 'lingxing',
                   'niuzhuan', 'qianyin', 'zhidong', '角速度', '_速度']
for sensor in sensor_list:
    _sudu_csv = cal_json[sensor][0]
    # print(_sudu_csv)
    cf = open(_sudu_csv, 'r')
    cf_csv = csv.reader(cf)
    # headers = next(cf_csv)
    # print(headers)

    sudu_list = []
    for row in cf_csv:
        # print(row)
        sudu_list.append(row[1])
    # print(sudu_list[0])
    # print(sudu_list[1])
    print(sensor)
    print(round(float(sudu_list[1])-float(sudu_list[0]),3))
    # print(sudu_list)

    # plt.plot(sudu_list[0:650])
    # plt.show()

    i = 0
    # while (i < len(sudu_list)-1):
    #     cal = float(sudu_list[i + 1]) - float(sudu_list[i])
    #     # print(cal)
    #     if round(cal,3) != 0.001:
    #         print('nega')
    #         print(i)
    #     i += 1
